#!/usr/bin/python3
# -*- coding: UTF-8 -*-

from app import App
from utils.tools import Tools
from utils.element import Element

import gol
gol._init()
from os import popen as osPopen, path as osPath  # 管道处理


class Application(App):
    # 初始配置
    def __init__(self):
        # python2 不支持 super().__init__()
        App().__init__()

        self._d = App()._d
        self.tool = Tools()

    # 首页 - 领京豆
    def getLJD(self):
        App().getNode("t", "领京豆")
        return self.getSJZJD()

    # ////////-----------------
    # 首页 - 升级赚京豆
    def getSJZJD(self):
        bNode, oNode = App().el2('p','//android.widget.ScrollView/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.view.ViewGroup[1]/android.view.ViewGroup[12]')
        if (oNode):
            bClick = oNode.click_exists(timeout=2)
            App().myEcho("升级赚京豆", bClick)
            return bClick
        return False

    # 首页 - 升级赚京豆 - 去完成
    def getQWC(self):
        return App().getNode("t", "去完成") 
    # ////////-----------------

    # ////////-----------------
    # 宠汪汪
    def getCWW(self):
        App().getNode("t", "我的")
        self.tool.setSleep(2)
        App().getNode("t", "宠汪汪")
        self.tool.setSleep(2)
        self._d.click(0.47, 0.578)

    # ////////-----------------

class Action(App):
    # 初始配置
    def __init__(self):
        # python2 不支持 super().__init__()
        App().__init__()
        self.tool = Tools()
        self.app = Application()
        self._d = App()._d

    def init(self):
        sAction = App().sAction
        if (sAction=='ljd'):
            if (self.app.getLJD()):
                while self.app.getQWC():
                    self.tool.setSleep(5)
                    self._d.press("back")
                    self.tool.setSleep(2)

        elif (sAction == 'test'):
            self.app.getSJZJD()

action = Action()
action.init()